package day02_Thread;

public class SleepDemo implements Runnable
{

    @Override
    public void run() {
        for (int i = 0; i < 50; i++) {
            System.out.println(Thread.currentThread().getName() + "---i---" + i);
            if (i == 20)
            {
                System.out.println(Thread.currentThread().getName() + "---礼让---");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args)
    {
        SleepDemo obj = new SleepDemo();
        Thread t1 = new Thread(obj,"t1");
        Thread t2 = new Thread(obj,"t2");
        Thread t3 = new Thread(obj,"t3");
        Thread t4 = new Thread(obj,"t4");
        Thread t5 = new Thread(obj,"t5");

        t1.setPriority(Thread.MIN_PRIORITY);
        t2.setPriority(Thread.MAX_PRIORITY);
        t3.setPriority(Thread.MAX_PRIORITY);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();

        for (int j = 0; j < 50; j++) {
            System.out.println(Thread.currentThread().getName() + "---j---" + j);
        }

    }


}
